package com.huike.review.service.impl;


import com.huike.common.utils.DateUtils;
import com.huike.review.mapper.MybatisReviewMapper;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * mybatis复习使用的业务层
 * 注意该业务层和我们系统的业务无关，主要是让同学们快速熟悉系统的
 */
@Service
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    private MybatisReviewMapper reviewMapper;


    @Override
    public int insertTbReview(String name, Integer age, String sex) {
        Review review = new Review();
        review.setSex(sex);
        review.setName(name);
        review.setAge(age);
//        review.setCreateBy(SecurityUtils.getUsername());
//        review.setUpdateBy(SecurityUtils.getUsername());
        Date now = DateUtils.getNowDate();
        review.setCreateTime(now);
        review.setUpdateTime(now);
        int rows = reviewMapper.insertReview(review);
        return rows;
    }

    @Override
    public int insertTbReview2(Review review) {
//        review.setCreateBy(SecurityUtils.getUsername());
//        review.setUpdateBy(SecurityUtils.getUsername());
        Date now = DateUtils.getNowDate();
        review.setCreateTime(now);
        review.setUpdateTime(now);
        int rows = reviewMapper.insertReview(review);
        return rows;
    }

    /**
     * =========================================================删除数据=============================================
     */
    @Override
    public int remove(Integer id) {
        return reviewMapper.remove(id);
    }

    /**
     * =========================================================修改数据=============================================
     */
    @Override
    public int updateReview(Review review) {
//        review.setUpdateBy(SecurityUtils.getUsername());
        Date now = DateUtils.getNowDate();
        review.setUpdateTime(now);
        return reviewMapper.updateReview(review);
    }

    /**
     * =========================================================查询数据的方法=============================================
     */
    @Override
    public Review getInfo(Long id) {
        return reviewMapper.selectOne(id);

    }

    @Override
    public List getDataByPage() {
        return reviewMapper.getDateByPage();
    }
}
